package org.adorsys.aderp.booking.web.ext;

import org.adorsys.aderp.aderplogin.client.UserDetailServiceClient;
import org.adorsys.aderp.aderplogin.domain.AderpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Displays information on the current user. Uses hessian to load user detail data
 * from aderp login.
 * 
 * @author fpo
 *
 *
 */
@Controller
@RequestMapping("/aderpusers")
public class AderpUserController {
	
	@Autowired
	private UserDetailServiceClient userDetailServiceClient;


    void addDateTimeFormatPatterns(Model uiModel) {
        uiModel.addAttribute("aderpUser_accountexpiration_date_format", "dd-MM-yyyy HH:mm");
        uiModel.addAttribute("aderpUser_credentialexpiration_date_format", "dd-MM-yyyy HH:mm");
    }

    @RequestMapping(produces = "text/html")
    public String show(Model uiModel) {
		AderpUser aderpUser = userDetailServiceClient.getAderpUser();
		uiModel.addAttribute("aderpuser", aderpUser);
        addDateTimeFormatPatterns(uiModel);
        uiModel.addAttribute("aderpuser", aderpUser);
        return "aderpusers/show";
    }
}
